<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"></meta>
    <title>医院后台转换</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/lib/dataTables.bootstrap.css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/paginate.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/table.css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/qulitity.css" type="text/css" type="text/css">
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <script>
        function addDevice() {
            window.parent.showModelIframe("${URL_HOSPTIALCONVERSION_TOADD}", "详细内容", 800, 600);
        }
        function updateDevice(){
            var checkedArray = getCheckedArray();
            if(checkedArray.length!=1){
                alert("请勾选一条数据修改");
                return;
            }
            window.parent.showModelIframe("${URL_HOSPTIALCONVERSION_TOUPDATE}?id="+checkedArray[0],"详细内容",800,400);
        }
        function deleteDevice(){
            var checkedArray = getCheckedArray();
            var ids = "";
            if(checkedArray.length==0){
                alert("请勾选至少一项数据");
                return;
            }else{
                for(var i=0; i<checkedArray.length;i++){
                    ids += checkedArray[i]+",";
                }
                ids = ids.substring(0,ids.length-1);
            }
            var r=confirm("确定要删除勾选的数据吗?");
            if(r==true){
                $.ajax({
                    url:'${URL_HOSPTIALCONVERSION_DELETE}',//删除地址
                    type:'post',
                    data:{ids:ids},
                    async : false, //默认为true 异步
                    error:function(){
                        alert('error');
                    },
                    success:function(data){
                        refreshTable();
                    }
                });
            }
        }
    </script>

</head>
<body>
<div class="wrap">
    <div class="page-header">
        <!-- /.page-header -->
        <ul class="page_nav">
            <li class="first cur">医卫士云平台&nbsp;&nbsp;&nbsp;&nbsp;&gt;&nbsp;&nbsp;&nbsp;&nbsp;</li>
            <li class="cur">数据管理&nbsp;&nbsp;&nbsp;&nbsp;&gt;&nbsp;&nbsp;&nbsp;&nbsp;</li>
            <li>医院后台转换</li>
        </ul>
    </div>

    <div class="form">
        <label>医卫士医院名:</label>
        <input id="myHospName" type="text" class="SN" placeholder="医卫士医院名">
        <%--<label>接入医院编码:</label>
        <input id="hospitalCode" type="text" class="SN" placeholder="接入医院编码">--%>
        <input id="query" type="button" value="搜索" class="search" onclick="refreshTable();">
        <span class="clear" onclick="cleanForm()">清除条件</span>
        <div></div>
    </div>
    <div id="tablepart">
        <table id="example" class="display" cellspacing="10" width="100%">
            <thead>
            <tr>
                <th><input id="all_id" type="checkbox"></th>
                <th>医卫士医院名</th>
                <th>接入医院编码</th>
                <th>登陆地址url</th>
                <th>检测报告大项url地址</th>
                <th>检测报告明细url地址</th>
                <th>创建时间</th>
                <th>更新时间</th>
            </tr>
            </thead>
        </table>
    </div>
</div>
<script>
    var table;

    var remarkShowLength = 20;//默认现实的字符串长度
    //切换显示备注信息，显示部分或者全部
    function changeShowRemarks(obj){//obj是td
        var content = $(obj).attr("content");
        if(content != null && content != ''){
            if($(obj).attr("isDetail") == 'true'){//当前显示的是详细备注，切换到显示部分
                //$(obj).removeAttr('isDetail');//remove也可以
                $(obj).attr('isDetail',false);
                $(obj).html(getPartialRemarksHtml(content));
            }else{//当前显示的是部分备注信息，切换到显示全部
                $(obj).attr('isDetail',true);
                $(obj).html(getTotalRemarksHtml(content));
            }
        }
    }
    //部分备注信息
    function getPartialRemarksHtml(remarks){
        return remarks.substr(0,remarkShowLength) + '&nbsp;&nbsp;<a href="javascript:void(0);" ><b>...</b></a>';
    }

    //全部备注信息
    function getTotalRemarksHtml(remarks){
        return remarks + '&nbsp;&nbsp;<a href="javascript:void(0);" >收起</a>';
    }

    function initTable() {
        table = $('#example').DataTable({
            "dom": "<'row'<'col-xs-2'l><'#mytool.col-xs-10'><'col-xs-6'f>r>" +
            "t" +
            "<'row'<'col-xs-6'i><'col-xs-6'p>>",
            "bFilter": false,//去掉搜索框
            "bAutoWidth": false, //自适应宽度
            "sPaginationType": "full_numbers",
            "ordering": false,//是否允许Datatables开启排序
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": "${URL_HOSPTIALCONVERSION_SEARCH}",
            "sAjaxDataProp": "dataList",//查询后，返回的集合
            "fnServerData": function (sSource, aoData, fnCallback) {  //查询条件
                aoData.push(
                    {"name": "myHospName", "value": $("#myHospName").val()}
                    /*{"name": "hospitalCode", "value": $("#hospitalCode").val()}*/
                );
                $.ajax({
                    "dataType": 'json',
                    "url": sSource,
                    "type": 'post',
                    "data": aoData,
                    "success": fnCallback
                });

            },

            "aoColumns" : [{
                "targets": -1,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {

                    $(nTd).html('' +
                        '&nbsp;&nbsp;<input name="id" value="' + oData.id + '" type="checkbox" onClick="isCheckedAll()">' +
                        '');
                }
            },{
                "mDataProp" : "myHospName"
            },{
                "mDataProp" : "hospitalCode"
            }, {
                "mDataProp" : "loginUrl"
            }, {
                "mDataProp" : "queryReportKindUrl"
            },{
                "mDataProp" : "queryReportDetailUrl"
            }, {
                "mDataProp" : "createTime"
            },{
                "mDataProp" : "updateTime"
            }],
            "createdRow": function (row, data, index) {
                if(data.queryReportKindUrl.length > remarkShowLength){//只有超长，才有td点击事件
                    $(row).children('td').attr('onclick','javascript:changeShowRemarks(this);');
                }
                $(row).children('td').attr('content',data.queryReportKindUrl);
                    if (data.queryReportKindUrl.length > 10) {
                        $('td:eq(8)', row).html( data.queryReportKindUrl.substr(0, 5));
                    }
////                    if (data.queryReportKindUrl.length > 10) {
//                        $('td:eq(11)', row).html( data.queryReportKindUrl.substr(0, 5));
//                    }

            },
            "columnDefs": [ {
                "targets": [4,5],
                "render": function (data, type, full, meta) {

                    //大项url...显示
                    if (full.queryReportKindUrl.length > remarkShowLength) {
                        return getPartialRemarksHtml(full.queryReportKindUrl);//显示部分信息
                    } else {
                        return full.queryReportKindUrl;//显示原始全部信息 }
                    }
                    //明细url...显示
                    if (full.queryReportDetailUrl.length > remarkShowLength) {
                        return getPartialRemarksHtml(full.queryReportDetailUrl);//显示部分信息
                    } else {
                        return full.queryReportDetailUrl;//显示原始全部信息 }
                    }
                }
            } ],

            "oLanguage": {//插件的汉化
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "当前显示 _START_ 到 _END_条 ,共 _TOTAL_ 条记录",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "上一页",
                    "sNext": "下一页",
                    "sLast": "末页"
                },
                "sZeroRecords": "没有检索到数据",
                "sProcessing": "<img src='' />",
                "sSearch": "搜索"
            },
            "initComplete": function () {
                $("#mytool").append('<button id="delete_butt" type="button" class="btn btn-outline btn-success" onclick="deleteDevice()" style="float:right;margin-right:10px;background: #35c990;border:none;">删除</button>');
                $("#mytool").append('<button id="update_butt" type="button" class="btn btn-outline btn-success" onclick="updateDevice()" style="float:right;;margin-right:10px;background: #35c990;border:none;">修改</button>');
                $("#mytool").append('<button id="add_butt" type="button" class="btn btn-outline btn-success" onclick="addDevice()" style="float:right;;margin-right:10px;background: #35c990;border:none;">新增</button>');
            }
        });
    }
    $(document).ready(function () {
        initTable();
//        $('#example tr th').eq(0).addClass('border_left');
//        $('#example tr th').eq(6).addClass('border_right');
        $('#example tbody tr td').addClass('active');
//        $('#example tr td').eq(6).addClass('border_right');
        $('#example_paginate').parent().addClass('pagewidth');
        $('#example_info').parent().addClass('showPage');
        $('#example_length').parent().addClass('pageNow');
    });
    //多选按钮
    $("#all_id").click(function(){
        if(this.checked){
            $("input[name='id']").each(function(){
                $(this)[0].checked = true;
            });
        }else{
            $("input[name='id']").each(function(){
                $(this)[0].checked = false;
            });
        }
    });

    //判断是否已经全选
    function isCheckedAll(){
        var isCheckAll = true;
        $("input[name='id']").each(function(){
            if(!this.checked){
                isCheckAll = false;
            }
        });
        if(isCheckAll){
            $("#all_id")[0].checked = true;
        }else{
            $("#all_id")[0].checked = false;
        }
    }

    function getCheckedArray(){
        var checkedArray = [];
        $("input[name='id']").each(function(){
            if(this.checked){
                checkedArray.push(this.value);
            }
        });
        return checkedArray;
    }
</script>
</body>
</html>